public class ReverseLinkedList {

        class Solution {
            /*递归解法
             public ListNode reverseList(ListNode head) {
                if(head==null||head.next==null) return head;
                ListNode node=reverseList(head.next);
                head.next.next=head;
                head.next=null;
                return node;
            }
             */
            //迭代解法(双指针)
            public ListNode reverseList(ListNode head) {
                ListNode prev = null;
                ListNode cur = head;
                ListNode temp = null;
                while (cur != null) {
                    temp = cur.next;// 保存下一个节点
                    cur.next = prev;
                    prev = cur;
                    cur = temp;
                }
                return prev;
            }

        }
  }

